﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Oxygen.IocModule;
using Oxygen.Server.Kestrel.Implements;
using System;
using System.Threading.Tasks;

namespace ClientSample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            await CreateDefaultHost(args).Build().RunAsync();
        }
        static IHostBuilder CreateDefaultHost(string[] args) => new HostBuilder()
            .ConfigureWebHostDefaults(webhostbuilder =>
            {
                // 注册成为oxygen服务节点
                webhostbuilder.StartOxygenServer<OxygenStartup>((config) =>{
                    config.Port = 80;
                    config.PubSubCompentName = "pubsub";
                    config.StateStoreCompentName = "statestore";
                    config.TracingHeaders = "Authentication";
                });
            })
            .ConfigureContainer<ContainerBuilder>(builder =>
            {
                // 注入oxygen依赖
                builder.RegisterOxygenModule();
                builder.RegisterType<ClientCallService>().As<IClientCallService>().InstancePerLifetimeScope();
                builder.RegisterType<HelloCallbackEventhandler>().As<HelloCallbackEventhandler>().InstancePerLifetimeScope();
            })
            .ConfigureLogging((hostingContext, logging) => 
            {
                logging.AddConsole();
            })
            .ConfigureServices((context,services)=>
            {
                services.AddAutofac();
            })
            .UseServiceProviderFactory(new AutofacServiceProviderFactory());
    }
}
